from django.db import models


class ShipSegment(models.Model):
    # 自定义自增主键
    ship_segments_id = models.AutoField(primary_key=True, verbose_name='分段ID')
    ship_number = models.CharField(max_length=50, verbose_name='船号')
    ship_type = models.CharField(max_length=100, verbose_name='船型')
    segment_number = models.CharField(max_length=50, verbose_name='分段号')
    station_cycle = models.CharField(max_length=100, null=True, blank=True, verbose_name='胎位周期')
    segment_length = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='分段长(m)')
    segment_width = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='分段宽(m)')
    segment_height = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='分段高(m)')
    segment_weight = models.DecimalField(max_digits=15, decimal_places=2, verbose_name='分段重量(t)')

    # 新增字段
    segment_category = models.CharField(max_length=100, null=True, blank=True, verbose_name='分段类型')
    segment_production = models.CharField(max_length=100, null=True, blank=True, verbose_name='分段产出')
    is_combined = models.BooleanField(default=False, verbose_name='是否组合分段')
    combined_segment = models.ForeignKey(
        'self',
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name='sub_segments',
        verbose_name='组合分段'
    )

    def __str__(self):
        return f"{self.ship_number} - {self.segment_number}"

    class Meta:
        db_table = 'ship_segments'
        verbose_name = '船舶分段信息'
        verbose_name_plural = '船舶分段信息列表'